﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineAuction.TemplateMaster
{
    public partial class WebForm10 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
                DienDuLieu();
        }

        private void DienDuLieu()
        {
            OnlineAuctionDataContext wsb = new OnlineAuctionDataContext();
            this.GridViewUser.DataSource = wsb.Accounts.ToList();
            this.GridViewUser.DataBind();
        }

        protected void GridViewUser_RowEditing(object sender, GridViewEditEventArgs e)
        {
            Response.Redirect("Edit.aspx");
        }

        protected void GridViewUser_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {
            this.GridViewUser.EditIndex = -1;
            DienDuLieu();
        }

        protected void GridViewUser_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            
        }

        protected void GridViewUser_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            string username = this.GridViewUser.Rows[e.RowIndex].Cells[0].Text;
            OnlineAuctionDataContext hdc = new OnlineAuctionDataContext();
           Account ac = hdc.Accounts.Where(h => h.username.Equals(username)).First();
           hdc.Accounts.DeleteOnSubmit(ac);
            hdc.SubmitChanges();
            DienDuLieu();
        }

        

       
    }
}